package pkg

import (
	"github.com/dgrijalva/jwt-go"
	"log"
	"time"
)

const (
	APP_KEY = "www.topgoer.com"
)

func TokenHandler(userId int64) (string, error) {
	// 颁发一个有限期一小时的证书
	token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
		"user": userId,
		"exp":  time.Now().Add(time.Hour * time.Duration(1)).Unix(),
		"iat":  time.Now().Unix(),
	})
	tokenString, err := token.SignedString([]byte(APP_KEY))
	if err != nil {
		log.Println("token生成失败")
	}
	return tokenString, nil
}
